package com.sky.controller.admin;

import com.sky.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
public class shopController {
    @Autowired
    private RedisTemplate redisTemplate;
    public static final String KEY="SHOP_STATUS";
    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status){
        log.info("设置店铺营业状态:{}",status==1?"营业中":"打烊中");
        // 将 Integer 转换为 String 后存储
        redisTemplate.opsForValue().set(KEY, String.valueOf(status));
        return Result.success();
    }

    @GetMapping("/status")
    public Result<Integer> getStatus(){
        // 获取时从字符串转换回Integer
        String statusStr = redisTemplate.opsForValue().get(KEY).toString();
        Integer status = statusStr != null ? Integer.valueOf(statusStr) : null;
        log.info("获取店铺营业状态:{}",status==1?"营业中":"打烊中");
        return Result.success(status);
    }
}
